<?php
define('ROOT',"d:/htdocs");
header('Content-Type:text/html;charset=GB2312');
require_once ROOT.'/global.common.php';
$root=$_SERVER[DOCUMENT_ROOT];
$type = $_POST['method'];
$gettype = $_GET['method'];

session_start();
if(!session_is_registered("oldw")){
session_register("oldw");
}
$oldw=$w;

if(!session_is_registered("oldh")){
session_register("oldh");
}
$oldh=$h;


function createdir($filepath){
   $nn=preg_split("/(?<!\:)\//",dirname($filepath));
   $temppath="";
   for($i=0;$i<count($nn);$i++){
	  $temppath.=(($i>0)?"/":"").$nn[$i];
		 if(!is_dir($temppath)){
			 @mkdir($temppath,0777);
	 }
  }
}

if($type==="uploadimg"){
   require_once ROOT.'/include/newphoto.php';   
   $upfos = new ieb_upload('img1',ROOT.'/upload');
   $old_file_name=$upfos -> getName(); 
   
   if($old_file_name){
	   $old_file_fooder=$upfos -> getExt();
	   
	   
	   if(strtolower($old_file_fooder)!='jpg'&&strtolower($old_file_fooder)!='gif'&&strtolower($old_file_fooder)!='png'&&strtolower($old_file_fooder)!='swf'){
		  $_SESSION['wrongstr'] = '�ϴ�ʧ�� ��֧��jpg��gif��png��swf�ļ���ʽ';
		  echo "<script>top.location='{$reurl}'</script>"; 
		  exit;
	   }
	   
	   $file_size=$upfos -> getSize();
	   if($file_size>4000000){
		  $_SESSION['wrongstr'] = '�ϴ�ʧ�� �ļ����Ϊ2��';
		  echo "<script>top.location='{$reurl}'</script>"; 
		  exit;
	   }
	
		
		   
		   $file_name=$upfos -> newName();
		   $upfos -> upload($file_name); 
		   if(strtolower($old_file_fooder)!='swf'){  
		   $upfos -> thumb("small_",830,120);
		   }
		   
		   $new_file_name = $upfos -> UpFile(); //$new_file_name �ϴ����ͼ��
		   $new_file_path = "http://www.ilaoyou.com/upload/".$new_file_name;

		   
		 if(strtolower($old_file_fooder)!='swf'){  
		   $small_file_name="small_".$new_file_name;  //$small_file_name ����ͼ��
		   $small_file_path = "http://www.ilaoyou.com/upload/".$small_file_name;
		   addWater($new_file_path,$waterPos);
		   addWater($small_file_path,$waterPos);
		 }

   }
   
   $w=($w==0)?"width100%":$w."px";
   $h=($h==0)?"100%":$h."px";
   
   if(strtolower($old_file_fooder)!='swf'){
   echo("<script>
	 window.returnValue='<img src=\"{$small_file_path}\">';
	 window.close()
   </script>");
   }else{
   echo("<script>
	 window.returnValue='<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"  title=\"titletext\" style=\"width:{$w};height:{$h};margin:-5px\"><param name=\"movie\" value=\"{$new_file_path}?".rand(0,1555)."\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\"><param name=\"Scale\" value=\"ShowAll\"><embed src=\"{$new_file_path}?".rand(0,1555)."\" scale=\"ShowAll\" wmode=\"transparent\" style=\"width:{$w};height:{$h};margin:0px;padding:0px\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" ></embed></object>';
	 window.close()
   </script>");   
   }
   exit;  
}



/* 
* ���ܣ�PHPͼƬˮӡ (ˮӡ֧��ͼƬ������) 
* ������ 
*      $groundImage    ����ͼƬ������Ҫ��ˮӡ��ͼƬ����ֻ֧��GIF,JPG,PNG��ʽ�� 
*      $waterPos        ˮӡλ�ã���10��״̬��0Ϊ���λ�ã� 
*                        1Ϊ���˾���2Ϊ���˾��У�3Ϊ���˾��ң� 
*                        4Ϊ�в�����5Ϊ�в����У�6Ϊ�в����ң� 
*                        7Ϊ�׶˾���8Ϊ�׶˾��У�9Ϊ�׶˾��ң� 
*      $waterImage        ͼƬˮӡ������Ϊˮӡ��ͼƬ����ֻ֧��GIF,JPG,PNG��ʽ�� 
*      $waterText        ����ˮӡ������������ΪΪˮӡ��֧��ASCII�룬��֧�����ģ� 
*      $textFont        ���ִ�С��ֵΪ1��2��3��4��5��Ĭ��Ϊ5�� 
*      $textColor        ������ɫ��ֵΪʮ��������ɫֵ��Ĭ��Ϊ#FF0000(��ɫ)�� 
* 
* ע�⣺Support GD 2.0��Support FreeType��GIF Read��GIF Create��JPG ��PNG 
*      $waterImage �� $waterText ��ò�Ҫͬʱʹ�ã�ѡ����֮һ���ɣ�����ʹ�� $waterImage�� 
*      ��$waterImage��Чʱ������$waterString��$stringFont��$stringColor������Ч�� 
*      ��ˮӡ���ͼƬ���ļ����� $groundImage һ���� 
* ���ߣ�longware @ 2004-11-3 14:15:13 
*/ 


function addWater($imgpath,$waterPos){
global $root;
	$imgpath=(substr($imgpath,0,1)=="/")?$root.$imgpath:$imgpath;
	
	if(is_file($imgpath)){
			   if($waterPos!="w"&&$waterPos!=""){
                   echo $imgpath."\r\n";
				   imageWaterMark($imgpath,$waterPos,"../image/sogxWLogo.png","",5,"");
			   }
	}
}

function imageWaterMark($groundImage,$waterPos=9,$waterImage="images/sy_5.png",$waterText="",$textFont=5,$textColor="#FF0000") 
{ 
    $isWaterImage = FALSE; 
    $formatMsg = "�ݲ�֧�ָ��ļ���ʽ������ͼƬ���������ͼƬת��ΪGIF��JPG��PNG��ʽ��"; 

    //��ȡˮӡ�ļ� 
    if(!empty($waterImage) && file_exists($waterImage)) 
    { 
        $isWaterImage = TRUE; 
        $water_info = getimagesize($waterImage); 
        $water_w    = $water_info[0];//ȡ��ˮӡͼƬ�Ŀ� 
        $water_h    = $water_info[1];//ȡ��ˮӡͼƬ�ĸ� 

        switch($water_info[2])//ȡ��ˮӡͼƬ�ĸ�ʽ 
        { 
            case 1:$water_im = @imagecreatefromgif($waterImage);break; 
            case 2:$water_im = imagecreatefromjpeg($waterImage);break; 
            case 3:$water_im = imagecreatefrompng($waterImage);break; 
            default:die($formatMsg); 
        } 
    } 

    //��ȡ����ͼƬ 
    if(!empty($groundImage) && file_exists($groundImage)) 
    { 
        $ground_info = @getimagesize($groundImage); 
        $ground_w    = $ground_info[0];//ȡ�ñ���ͼƬ�Ŀ� 
        $ground_h    = $ground_info[1];//ȡ�ñ���ͼƬ�ĸ� 

        switch($ground_info[2])//ȡ�ñ���ͼƬ�ĸ�ʽ 
        { 
            case 1:$ground_im = imagecreatefromgif($groundImage);break; 
            case 2:$ground_im = imagecreatefromjpeg($groundImage);break; 
            case 3:$ground_im = imagecreatefrompng($groundImage);break; 
            default:die($formatMsg); 
        } 
    } 
    else 
    { 
        die("��Ҫ��ˮӡ��ͼƬ�����ڣ�"); 
    } 

    //ˮӡλ�� 
    if($isWaterImage)//ͼƬˮӡ 
    { 
        $w = $water_w; 
        $h = $water_h; 
        $label = "ͼƬ��"; 
    } 
    else//����ˮӡ 
    { 
        $temp = imagettfbbox(ceil($textFont*2.5),0,"./cour.ttf",$waterText);//ȡ��ʹ�� TrueType ������ı��ķ�Χ 
        $w = $temp[2] - $temp[6]; 
        $h = $temp[3] - $temp[7]; 
        unset($temp); 
        $label = "��������"; 
    } 
    if( ($ground_w<$w) || ($ground_h<$h) ) 
    { 
        echo "��Ҫ��ˮӡ��ͼƬ�ĳ��Ȼ��ȱ�ˮӡ".$label."��С���޷�����ˮӡ��"; 
        return; 
    } 
    switch($waterPos) 
    { 
        case 0://��� 
            $posX = rand(0,($ground_w - $w)); 
            $posY = rand(0,($ground_h - $h)); 
            break; 
        case 1://1Ϊ���˾��� 
            $posX = 0; 
            $posY = 0; 
            break; 
        case 2://2Ϊ���˾��� 
            $posX = ($ground_w - $w) / 2; 
            $posY = 0; 
            break; 
        case 3://3Ϊ���˾��� 
            $posX = $ground_w - $w; 
            $posY = 0; 
            break; 
        case 4://4Ϊ�в����� 
            $posX = 0; 
            $posY = ($ground_h - $h) / 2; 
            break; 
        case 5://5Ϊ�в����� 
            $posX = ($ground_w - $w) / 2; 
            $posY = ($ground_h - $h) / 2; 
            break; 
        case 6://6Ϊ�в����� 
            $posX = $ground_w - $w; 
            $posY = ($ground_h - $h) / 2; 
            break; 
        case 7://7Ϊ�׶˾��� 
            $posX = 0; 
            $posY = $ground_h - $h; 
            break; 
        case 8://8Ϊ�׶˾��� 
            $posX = ($ground_w - $w) / 2; 
            $posY = $ground_h - $h; 
            break; 
        case 9://9Ϊ�׶˾��� 
            $posX = $ground_w - $w; 
            $posY = $ground_h - $h; 
            break; 
        default://��� 
            $posX = rand(0,($ground_w - $w)); 
            $posY = rand(0,($ground_h - $h)); 
            break;     
    } 

    //�趨ͼ��Ļ�ɫģʽ 
    imagealphablending($ground_im, true); 

    if($isWaterImage)//ͼƬˮӡ 
    { 
        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//����ˮӡ��Ŀ���ļ�         
    } 
    else//����ˮӡ 
    { 
        if( !empty($textColor) && (strlen($textColor)==7) ) 
        { 
            $R = hexdec(substr($textColor,1,2)); 
            $G = hexdec(substr($textColor,3,2)); 
            $B = hexdec(substr($textColor,5)); 
        } 
        else 
        { 
            die("ˮӡ������ɫ��ʽ����ȷ��"); 
        }
        imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));         
    } 

    //����ˮӡ���ͼƬ 
    @unlink($groundImage); 
    switch($ground_info[2])//ȡ�ñ���ͼƬ�ĸ�ʽ 
    { 
        case 1:imagegif($ground_im,$groundImage);break; 
        case 2:imagejpeg($ground_im,$groundImage);break; 
        case 3:imagepng($ground_im,$groundImage);break; 
        default:die($errorMsg); 
    } 

    //�ͷ��ڴ� 
    if(isset($water_info)) unset($water_info); 
    if(isset($water_im)) imagedestroy($water_im); 
    unset($ground_info); 
    imagedestroy($ground_im); 
} 

?>   
    
   
   
   